<?php
include_once '../inc/global.php';

//note 判断是否锁屏
function is_lock(){
	if( isset( $_SESSION['lock_screen'] ) && $_SESSION['lock_screen'] == 1 ){
		echo 'yes';
	}
}

//note 锁屏
function lock(){
	$_SESSION['lock_screen'] = 1;
	$_SESSION['open_lock_test_num'] = 0;	
}
	
//note 解锁
function open_lock(){
	$pw = $_GET['lock_password'];	
	
	if( md5($pw) == $_SESSION['APwd'] ){
		$_SESSION['lock_screen'] = 0;
		$_SESSION['open_lock_test_num'] = 0;
	}else{
		$_SESSION['open_lock_test_num'] = $_SESSION['open_lock_test_num'] + 1;		
		if( $_SESSION['open_lock_test_num'] == 3 ){
			$_SESSION['user'] = null;
			$_SESSION['lock_screen'] = 0;
			$_SESSION['open_lock_test_num'] = 0;			
			echo 'exit';
		}else{
			echo 'err|'.(3-$_SESSION['open_lock_test_num']);
		}
	}
}

//note 编辑菜单名称
function menu_edit(){
	global $db;
	$mid = $_GET['mid'];
	$name = $_GET['name'];
	$ret = $db->update('menu', array('name'=>$name),'mid='.$mid);
	echo $ret ? 1 : 0;
}

//note 管理员管理里的导航菜单未选择,返回属于导航菜单下的所有模块ID
function menu_no_select(){
	global $db;
	$mid = $_GET['mid'];//一级菜单ID
	
	//二级菜单ID
	$sql = "SELECT mid FROM menu WHERE pid = {$mid}";
	$ret = $db->getAll( $sql );
	$arr = array();
	foreach( $ret as $v ){
		$arr[] = $v['mid'];
	}
		
	//在一级菜单ID下的所有模块ID
	$arr[] = $mid;
	$str = empty( $arr ) ? 0 : implode(',',$arr);
	$sql = "SELECT MID FROM Mould WHERE Menu_id IN({$str})";
	$ret = $db->getAll( $sql );
	$arr_2 = array();
	foreach( $ret as $v ){
		$arr_2[] = $v['MID'];
	}
	
	echo empty( $arr_2 ) ? '' : implode(',', $arr_2);
}



$m = $_GET['m'];
call_user_func( $m );

?>